package com.quyl.poi.util;

import org.springframework.core.io.ClassPathResource;
import org.springframework.util.FileCopyUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * Css样式文件复制操作
 */
public class CssUtil {

    public static void copyCssStyle(String filePath) {
        try {
            //复制css样式
            ClassPathResource cpr = new ClassPathResource("static/style.css");
            byte[] bdata = FileCopyUtils.copyToByteArray(cpr.getInputStream());
            String data = new String(bdata, StandardCharsets.UTF_8);
            byte[] sourceByte = data.getBytes();
            File file = new File(filePath + Constant.STYLE_CSS);//文件路径（路径+文件名）
            if (!file.exists()) {   //文件不存在则创建文件，先创建目录
                File dir = new File(file.getParent());
                dir.mkdirs();
                file.createNewFile();
            }
            FileOutputStream outStream = new FileOutputStream(file); //文件输出流将数据写入文件
            outStream.write(sourceByte);
            outStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
        }
    }
}
